<template>
  <div class="titleRandom">
    <div class="form-warp-random">
      <div class="titleRandom-box">
        <div class="dotRandom"></div>
        <div class="titleRandom">
          {{title}}
          <slot name="titleRandom"></slot>
        </div>
        <span class="iconRandom" @click="collapse = !collapse" v-if="!hideCollapse">
          <i :class="collapse?'el-icon-arrow-down':'el-icon-arrow-up'"></i>
        </span>
        <div v-if="titleGray !== ''" class="titleRandomGray">{{titleGray}}</div>
        <div class="titleRandom-suffix">
          <slot name="title-suffix"></slot>
        </div>
      </div>
      <div v-show="collapse">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "formtitle",
  props: {
    title: {
      type: String
    },
    titleGray: {
      type: String,
      default: ''
    },
    hideCollapse: {
      type: Boolean,
      default: true
    },
    defaultOpen: { // 默认展开
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      collapse: this.defaultOpen
    };
  }
};
</script>

<style lang="scss" scoped>
.form-warp-random {
  background: #ffffff;
  margin: 0 10px 10px 10px;
  .titleRandom-box {
    position: relative;
    padding: 20px 0;
    display: flex;
    align-items: center;
    .dotRandom {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color: #4A75D0;
    }
    .titleRandom {
      margin: 0 8px;
      color: #4d4d4d;
      font-size: 16px;
      font-family: PingFangSC;
      font-weight: 600;
    }
    .titleRandomGray{
      color: #A0A0A0;
      font-size: 16px;
      margin-left: 10px;
    }
    .titleRandom-suffix {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
    }
    .iconRandom {
      cursor: pointer;
    }
  }
}
</style>
